<?php
// <copyright file="AuthenticationType.cs" company="NQtec">
// Copyright (c) 2008, 2009 All Right Reserved, http://www.dqer.com/
// Copyright (c) 2008, 2009 All Right Reserved, http://www.nqtec.com/
//
// This source is part of the DQER library that released under the LGPL.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Victor Gatkov</author>
// <email>v.gatkov@nqtec.com</email>
// <email>info@dqer.com</email>
// <date>2008-09-11</date>
// <summary>Contains a base, abstract class for an AuthorisationPolicyProvider</summary>

class RenderForm {

//   var $renderform;
//   var $other;
//   function RenderForm() {
//      $this->startRenderForm();
//   }
//   function startRenderForm(){
//      return 1;
//   }

function form_close($val="Submit") {
 $this->set_tx(); // !!!!!!!!!
// if (isset($_GET['next'])) $this->hifield("next",$_GET['next']); // sanitize!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 if(FORM_SEC=='CAPTCHA'){$this->captcha();$this->form_submit($val);}
 if(FORM_SEC=='NONE'){$this->form_submit($val);}
 echo"               </form>\n";
 echo"            </fieldset>\n";
 echo"         </div><!-- End of contactform -->\n";
}

function form_open($id, $caption, $exec_path, $extra="") {
 if(FORM_SEC=='JS'){$extra.="class=\"xa\"";}
 if(PGTP=='sign' && PASS_ENC){$extra.=" onSubmit=\"return login(this);\"";}
 echo"         <div id=\"".$id."\">\n";
 echo"            <fieldset>\n";
// echo"            <legend>".$caption."</legend>\n";

 $this->prerrors(); // add lang

 echo"               <form action=\"".$exec_path."\" method=\"post\" ".$extra.">\r";
}

function form_open_get($id, $caption, $exec_path, $extra="") {
 echo"         <div id=\"".$id."\">\n";
 echo"            <fieldset>\n";
// echo"            <legend>".$caption."</legend>\n";

 $this->prerrors(); // add lang

 echo"               <form action=\"".$exec_path."\" method=\"get\" ".$extra.">\r";
}

function form_submit($val,$name="Submit") {
 if(FORM_BUTTON=='IMG'){echo"                 <input type=\"image\" src=\"".$src."\" alt=\"".$alt."\" name=\"".$name."\" value=\"".$val."\" />\n";}
 else{echo"                 <div><label><input class=\"jbutton\" type=\"submit\" name=\"".$name."\" value=\"".$val."\" /></label></div>\n";}
}

function set_tx(){
 global $session;
 $tx = md5(uniqid(rand(), true));
 $session->set_tx($tx);
 $this->hifield("tx",$tx);
}

function captcha() {
 global $form, $session;
 $len               = 5;
 $zz                = '';
// if ($session->is_signed()) return;
  for($i=0;$i<$len;$i++) $zz .= chr(rand(48,57));
   $session->set_xb($zz);


 echo"                 <div class=\"clr\">\n";
 echo"                    <label for=\"xa\">\n";
// echo"                    <small>Type the digits that you see in the picture</small><br />\n";
 echo"                    <small>Turing Number</small><br />\n";
 echo"                    <input name=\"xa\" id=\"xa\" type=\"text\" size=\"$len\" maxlength=\"$len\" value=\"\" autocomplete=\"off\" />\n";
 echo"                    <img src=\"".CAPTCHA_PATH."/\" height=\"30\" width=\"140\" alt=\"\" />\n";
 echo"                    <span class=\"colerr\">".$form->error("xa")."</span>\n";
 echo"                    </label>\n";
 echo"                 </div>\n";
//echo $session->get_xb();
}

function tos() {
 global $form;
 if ($form->value("tos")=='on') $ttch = " checked"; else $ttch = "";
 echo"                 <div class=\"clr\">\n";
 echo"                    <label>I have read, understand and ACCEPT<br /> Terms of Service<br /><input type=\"checkbox\" name=\"tos\"".$ttch." />\n";
 echo"                    <span class=\"colerr\">".$form->error("tos")."</span>\n";
 echo"                    <br /><small>See Terms Of Service <a href=\"http://www.".DOMAIN."/tos/\" onclick=\"target='_blank';\">here</a></small>\n";

 echo"                    </label>\n";
 echo"                 </div>\n";
}
function chik($nam, $nn='', $def='') {
 global $form;
 if ($form->value($nam)=='on' || $def=='on') $ttch = " checked"; else $ttch = "";
 if ($nn=='') $nn = $nam;
 echo"                 <div class=\"clr\">\n";
 echo"                    <label for=\"".$nn."\">$nam<br /><input type=\"checkbox\" name=\"$nn\"".$ttch." />\n";
 echo"                    <span class=\"colerr\">".$form->error($nn)."</span>\n";
 echo"                    </label>\n";
 echo"                 </div>\n";
}
function prerrors() {
 global $form;
 if($form->num_errors > 0) {
    echo "<br /><span class=\"colerr\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !!! FORM REJECTED !!! --=> ".$form->num_errors." error(s) found within form ::</span>";
 }
}

function txfield($nn, $nnn, $ss, $ll, $cont="") {
 global $form;
 echo"               <div class=\"clr\">\n";
 echo"                  <label for=\"".$nnn."\">".$nn."<br />\n";
// echo"                  <textarea rows=\"".$ss."\" cols=\"".$ll."\" name=\"".$nnn."\" type=\"text\" id=\"".$nnn."\" value=\"".$cont."\" />$cont</textarea><span class=\"colerr\">".$form->error($nnn)."</span></label>\n";
echo"                  <textarea rows=\"".$ss."\" cols=\"".$ll."\" name=\"".$nnn."\" id=\"".$nnn."\">$cont</textarea><span class=\"colerr\">".$form->error($nnn)."</span></label>\n";
 echo"               </div>\n";
}

function jifield($nn, $nnn, $ss, $ll, $vv="") {
 global $form;
 if($form->value($nnn)=='') $value = $vv; else $value = $form->value($nnn);
 echo"               <div class=\"clr\">\n";
 echo"                  <label for=\"".$nnn."\"><small>".$nn."</small><br />\n";
 echo"                  <input name=\"".$nnn."\" type=\"text\" id=\"".$nnn."\" size=\"".$ss."\" maxlength=\"".$ll."\" value=\"".$value."\" /><span class=\"colerr\">".$form->error($nnn)."</span></label>\n";
 echo"               </div>\n";
}
function pifield($nn, $nnn, $ss, $ll) {
 global $form;
 echo"               <div class=\"clr\">\n";
 echo"                  <label for=\"".$nnn."\"><small>".$nn."</small><br />\n";
 echo"                  <input name=\"".$nnn."\" type=\"password\" id=\"".$nnn."\" size=\"".$ss."\" maxlength=\"".$ll."\" value=\"\" /><span class=\"colerr\">".$form->error($nnn)."</span></label>\n";
 echo"               </div>\n";
}
function rifield($nn, $nnn, $ss, $vv) {
 echo"               <div class=\"clr\">\n";
 echo"                  <label for=\"".$nnn."\"><small>".$nn."</small><br />\n";
 echo"                  <input class=\"colerr\" name=\"".$nnn."\" type=\"text\" id=\"".$nnn."\" size=\"".$ss."\"  value=\"".$vv."\" readonly=\"1\" /></label>\n";
 echo"               </div>\n";
}

function fffield($nn, $nnn, $ss, $ll) {
 global $form;
 echo"               <div class=\"clr\">\n";
 echo"                  <label for=\"".$nnn."\">".$nn."<br />\n";
 echo"                  <input name=\"".$nnn."\" type=\"file\" id=\"".$nnn."\" size=\"".$ss."\" maxlength=\"".$ll."\" value=\"\" /><span class=\"colerr\">".$form->error($nnn)."</span></label>\n";
 echo"               </div>\n";
}

function hifield($name, $val="") {
 global $form;
 if($form->value($name)!='') $val = $form->value($name);
 echo"               <div class=\"clr\">\n";
 echo "                 <input type=\"hidden\" name=\"".$name."\" value=\"".$val."\" />\r";
 echo"               </div>\n";
}


function ccurr($val='') {
 global $form;

 $cn = array(1=>"European, Euro",
               2=>"United States, Dollar",
               3=>"Canada, Dollar",
               4=>"Australia, Dollar",
               5=>"Switzerland, Franc",
               6=>"United Kingdom, Pound",
               7=>"Japan, Yen",
               8=>"South Africa, Rand",
               9=>"China, Yuan",
               10=>"Brazil, Real",
               11=>"Gold, Troy oz");


 $cc = array(1=>"EUR",
               2=>"USD",
               3=>"CAD",
               4=>"AUD",
               5=>"CHF",
               6=>"GBP",
               7=>"JPY",
               8=>"ZAR",
               9=>"CNY",
               10=>"BRL",
               11=>"XAU");


echo"               <div class=\"clr\">\n";
echo"                  <label for=\"ccurr\"><small>Preferred Currency</small><br />\n";
echo"                  <select name=\"ccurr\" id=\"ccurr\" style=\"width: 200px\">\n";
echo"                   <option value=\"\">Currency</option>\n";

                        for ($i=1; $i<=11; $i++) {
                            echo"                     <option value=\"$cc[$i]\"";
                            if($cc[$i]==$form->value("ccurr") || $cc[$i]==$val) {
                               echo" selected >$cn[$i]</option>\n";
                            } else {
                              echo">$cn[$i]</option>\n";
                            }
                        }

 echo"                    </select><span class=\"colerr\">".$form->error("ccurr")."</span></label>\n";
 echo"                 </div>\n";

}


function ttlfield($val='') {
 global $form;
 echo"                 <div class=\"clr\">\n";
 echo"                    <label for=\"title\"><small>Title</small><br />\n";
 echo"                    <select name=\"title\" id=\"title\" style=\"width: 60px\">\n";
                      if($form->value("title")=='' || $val=='')
                         echo"                    <option value=\"\" selected>N/A</option>\n";
                      else
                         echo"                    <option value=\"\">N/A</option>\n";
                      if($form->value("title")=='Ms' || $val=='Ms')
                         echo"                     <option value=\"Ms\" selected>Ms</option>\n";
                      else
                         echo"                     <option value=\"Ms\">Ms</option>\n";
                      if($form->value("title")=='Mr' || $val=='Mr')
                         echo"                     <option value=\"Mr\" selected>Mr</option>\n";
                      else
                         echo"                     <option value=\"Mr\">Mr</option>\n";
                      if($form->value("title")=='Mrs' || $val=='Mrs')
                         echo"                     <option value=\"Mrs\" selected>Mrs</option>\n";
                      else
                         echo"                     <option value=\"Mrs\">Mrs</option>\n";
                      if($form->value("title")=='Dr' || $val=='Dr')
                         echo"                     <option value=\"Dr\" selected>Dr</option>\n";
                      else
                         echo"                     <option value=\"Dr\">Dr</option>\n";
 echo"                    </select><span class=\"colerr\">".$form->error("title")."</span></label>\n";
 echo"                 </div>\n";
}
function dnfield() {
 global $form;
 $nnn = "dnn";
 $ss  = 32;
 $ll  = 32;
 $value = $form->value($nnn);

 echo"                 <div class=\"clr\">\n";
 echo"                    <label for=\"dnn\">Domain<br />\n";
 echo"WWW.<input name=\"".$nnn."\" type=\"text\" id=\"".$nnn."\" size=\"".$ss."\" maxlength=\"".$ll."\" value=\"".$value."\" /><span class=\"colerr\">".$form->error($nnn)."</span>";
 echo"                    .<select name=\"dn\" id=\"dn\">\n";
                      if($form->value("dn")=='n')
                         echo"                    <option value=\"n\" selected>N/A</option>\n";
                      else
                         echo"                    <option value=\"n\">N/A</option>\n";
                      if($form->value("dn")=='com')
                         echo"                     <option value=\"com\" selected>com</option>\n";
                      else
                         echo"                     <option value=\"com\">com</option>\n";
                      if($form->value("dn")=='net')
                         echo"                     <option value=\"net\" selected>net</option>\n";
                      else
                         echo"                     <option value=\"net\">net</option>\n";
 echo"                    </select><span class=\"colerr\">".$form->error("dn")."</span></label>\n";
 echo"                 </div>\n";
}
function dbfield($minor_age, $max_age, $month_lang, $val=0) {
 global $form;
 $minors_out = date("Y")-$minor_age;
 $olders_out = date("Y")-$max_age;

 if ($val!=0) {
     $ddt = strtotime($val);
     $val_day    = date('d', $ddt);
     $val_month  = date('m', $ddt);
     $val_year   = date('Y', $ddt);
 }

if ($month_lang == 'gbr') {
 $mont = array(1=>"January",
               2=>"February",
               3=>"March",
               4=>"April",
               5=>"May",
               6=>"June",
               7=>"July",
               8=>"August",
               9=>"September",
               10=>"October",
               11=>"November",
               12=>"December");
}

echo"               <div class=\"clr\">\n";
echo"                  <label for=\"day\"><small>Date of birth</small><br />\n";
echo"                  <select name=\"day\" id=\"day\" style=\"width: 54px\">\n";
echo"                   <option value=\"\">Day</option>\n";

                        for ($i=1; $i<=31; $i++) {
                           $aa = $i;
                           if($aa <= 9) $aa = "0".$i;

                           echo"                     <option value=\"$aa\"";
                           if($aa==$form->value("day") || $aa==$val_day) {
                              echo" selected >$aa</option>\n";
                           } else {
                              echo">$aa</option>\n";
                           }
                        }

echo"                  </select>\n";
echo"                  <select name=\"month\">\n";
echo"                   <option value=\"\">Month</option>\n";

                    for ($i=1; $i<=12; $i++) {
                       $aa = $i;
                       if($aa <= 9) $aa = "0".$i;

                       echo"                     <option value=\"$aa\"";
                       if($aa==$form->value("month") || $aa==$val_month) {
                          echo" selected >$mont[$i]</option>\n";
                       } else {
                          echo">$mont[$i]</option>\n";
                       }

                    }

echo"                 </select>\n";
echo"                 <select name=\"year\" style=\"width: 60px\">\n";
echo"                  <option value=\"\">Year</option>\n";

                    for ($i=$minors_out; $i>=$olders_out; $i--) {
                       echo"                     <option value=\"$i\"";
                       if($i==$form->value("year") || $i==$val_year) {
                          echo" selected >$i</option>\n";
                       } else {
                          if ($i==$olders_out) {
                              echo">".$i."-</option>\n";
                          } else {
                              echo">".$i."</option>\n";
                          }
                       }
                    }
echo"                    </select><span class=\"colerr\">".$form->error("dob")."</span></label>\n";
echo"                 </div>\n";
}
function gtz($sel) {
 global $form, $database;
echo"               <div class=\"clr\">\n";
echo"                  <label for=\"gtz\"><small>Time Zone</small><br />\n";
echo"                  <select name=\"gtz\" id=\"gtz\" style=\"width: 230px\">\n";
echo"                   <option value=\"\">TimeZone</option>\n";

   $q            = "SELECT * FROM ".TBL_GTZ." ORDER BY `gtz` ASC"; 
   $result       = mysql_query($q);
   while ($row=mysql_fetch_array($result)) {
                           $aa   =  $row['gtz'];
                           echo"                     <option value=\"$aa\"";
                           if($aa==$form->value("gtz") || $aa==$sel) {
                              echo" selected >$aa</option>\n";
                           } else {
                              echo">$aa</option>\n";
                           }
   }

echo"                  </select></label>\n";
echo"                  </div>\n";
}
function ccountry($sel) {
 global $form, $database;
echo"               <div class=\"clr\">\n";
echo"                  <label for=\"country\"><small>Country</small><br />\n";
echo"                  <select name=\"country\" id=\"country\" style=\"width: 230px\">\n";
echo"                   <option value=\"\">Country</option>\n";

   $q            = "SELECT * FROM ".TBL_ISO." ORDER BY `cname` ASC"; 
   $result       = mysql_query($q);
   while ($row=mysql_fetch_array($result)) {
                           $a3   =  $row['a3'];
                           $cn   =  $row['cname'];
                           echo"                     <option value=\"$a3\"";
                           if($a3==$form->value("country") || $a3==$sel) {
                              echo" selected >$cn</option>\n";
                           } else {
                              echo">$cn</option>\n";
                           }
   }

echo"                  </select></label>\n";
echo"                  </div>\n";
}
function cllfield($cid) {
 global $form, $database;
echo"               <div class=\"clr\">\n";
echo"                  <label for=\"clang\"><small>Language</small><br />\n";
echo"                  <select name=\"clang\" id=\"clang\" style=\"width: 230px\">\n";
echo"                   <option value=\"\">Language</option>\n";

   $q            = "SELECT * FROM ".TBL_LANG." ORDER BY `name` ASC"; 
   $result       = mysql_query($q);
   while ($row=mysql_fetch_array($result)) {
                           $code   =  $row['code'];
                           $name   =  $row['lname'];
                           echo"                     <option value=\"$code\">$name</option>\n";
   }

echo"                  </select></label>\n";
echo"                  </div>\n";
}
function ctagfield() {
 global $form, $database;
echo"               <div class=\"clr\">\n";
echo"                  <label for=\"ctag\"><small>Category</small><br />\n";
echo"                  <select name=\"ctag\" id=\"ctag\" style=\"width: 140px\">\n";
echo"                   <option value=\"\">Tag</option>\n";

   $q            = "SELECT * FROM ".TBL_BM." WHERE `status`>0 GROUP BY `topic`"; 
   $result       = mysql_query($q);
   while ($row=mysql_fetch_array($result)) {
                           $tag   =  $row['topic'];
//                           echo"                     <option value=\"$tag\">".ucwords($tag)."</option>\n";
                           if($tag==$form->value("ctag")) {
                              echo" <option value=\"$tag\" selected>".ucwords($tag)."</option>\n";
                           } else {
                              echo" <option value=\"$tag\">".ucwords($tag)."</option>\n";
                           }
   }

echo"                  </select></label>\n";
echo"                  </div>\n";
}

};

?>
